package com.ybzl.gateway.controller;

import com.ybzl.gateway.domain.*;
import com.ybzl.gateway.domain.dto.FenceDTO;
import com.ybzl.gateway.service.IFenceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("fence/")
@Slf4j
public class FenceController {
    @Autowired
    private IFenceService fenceService;


    @PostMapping("add")
    public Result add(@RequestBody FenceDTO fenceDTO) {
        int flag = fenceService.saveOrUpdate(fenceDTO);
        if (flag != 0) {
            return new Result(200, null, true);
        } else {
            return new Result(400, null, false);
        }
    }

    @PostMapping("del")
    public Result del(@RequestBody FenceDTO fenceDTO) {
        int flag = fenceService.delByTs(fenceDTO.getTs());
        if (flag != 0) {
            return new Result(200, null, true);
        } else {
            return new Result(400, null, false);
        }
    }

    @GetMapping("list")
    public Result list() {
        List<Fence> list = fenceService.selectFence();
        return new Result(200, list, true);
    }

}
